<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
            list-style: none;
        }
        .main{
            width: 500px;
            margin: 0 auto;
            background: aqua;
        }
        li{
            height: 30px;
            line-height: 30px;
        }
    </style>
</head>
<body>
    <ul class="main" id="main">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
    </ul>
</body>
</html>
<script>
    var lis=document.querySelectorAll("li");
    for(var i=0;i<lis.length;i++){
        if(i%2==0){
            lis[i].style.backgroundColor="pink";
        }else{
            lis[i].style.backgroundColor="yellow";
        }
        lis[i].onmouseover=function(){
            this.bgColor=this.style.backgroundColor;
            this.style.background="red";
        }
        lis[i].onmouseout=function(){
            this.style.background=this.bgColor;
        }
    }
</script>